package worker;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable;

import downloader.TextFileDownloader;
import file.search.SearchUtility;

abstract class AbstractSearch implements Callable<String> {

	protected Map<String,Integer> counter = null; 
	protected BlockingQueue<String> urlQueue = null;
	protected String localFile = null;
	protected Set<String> searchStringSet = null;
	
	public AbstractSearch(BlockingQueue<String> queue,Set<String> searchStringSet) {
		this.urlQueue = queue;
		this.searchStringSet = searchStringSet;
	}	
	protected void download(String url){
		TextFileDownloader downloader = new TextFileDownloader(url);
		downloader.download();
		this.localFile = downloader.getFileName();
	}
	
	protected void search(){
		SearchUtility utility = new SearchUtility(this.localFile, searchStringSet);
		counter = utility.search();
	}
	protected void init(){
		counter = null;
		localFile = null;
	}
}
